import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore(
  'app',
  () => {
    const collapsed = ref(false)
    const theme = ref<'light' | 'dark'>('light')

    const toggleCollapsed = () => {
      collapsed.value = !collapsed.value
    }

    const toggleTheme = () => {
      theme.value = theme.value === 'light' ? 'dark' : 'light'
    }

    return {
      collapsed,
      theme,
      toggleCollapsed,
      toggleTheme,
    }
  },
  {
    // 启用持久化
    persist: {
      enabled: true,
      strategies: [
        {
          key: 'admin_app',
          storage: localStorage,
          paths: ['collapsed', 'theme'],
        },
      ],
    },
  }
)
